package gui.advertiser;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.MatteBorder;

import application.ArenaManager;

public class HandleAccountBalanceGUI extends JPanel {

	private JLabel lblAmount;
	private JLabel lblAdvertisementAmount;
	private JPanel accountPanel;

	/**
	 * Create the panel.
	 */
	public HandleAccountBalanceGUI() {
		setLayout(new BorderLayout(0, 0));

		JPanel panel = new JPanel();
		add(panel, BorderLayout.SOUTH);

		JButton btnNewButton = new JButton("Add Amount");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				showAmountDialog();
				setAmount();
			}
		});
		panel.add(btnNewButton);

		accountPanel = new JPanel();
		accountPanel.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0,
				0, 0)));
		add(accountPanel, BorderLayout.CENTER);
		accountPanel.setLayout(null);

		JLabel lblCurrentAccount = new JLabel("Current account balance:");
		lblCurrentAccount.setBounds(10, 11, 125, 14);
		accountPanel.add(lblCurrentAccount);

		lblAmount = new JLabel();
		lblAmount.setBounds(20, 36, 74, 14);
		initAmount();
		accountPanel.add(lblAmount);

		lblAdvertisementAmount = new JLabel();
		lblAdvertisementAmount.setText("Kr");
		lblAdvertisementAmount.setBounds(100, 36, 35, 14);
		accountPanel.add(lblAdvertisementAmount);
	}

	private void showAmountDialog() {
		new AddAmountDialog();
	}
	
	private void initAmount() {
		double amount = ArenaManager.getInstance().getFounds();
		lblAmount.setText("" + amount);
	}

	public void setAmount() {
		
		double amount = ArenaManager.getInstance().getFounds();
		lblAmount.setText("" + amount);

		lblAmount.updateUI();
		lblAmount.repaint();

	}

}
